import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';

enum Api {
  list = '/exam/labExam/userExamList',
  save = '/exam/labExam/add',
  edit = '/exam/labExam/edit',
  queryPaper = '/exam/paper/labExamPaper/createPaper',
  updateQuAnswere = '/exam/paper/labExamPaper/updateQuAnswere',
  submitPaper = '/exam/paper/labExamPaper/submitPaper',
  queryByEIdAndUId = '/exam/paper/labExamPaper/queryByEIdAndUId',
}



/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });


/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}


/**
 * 查询考试
 * @param params
 */
export const queryPaper = (params) => defHttp.get({ url: Api.queryPaper, params });

/**
 * 更新试题答案
 * @param params
 */
export const updateQuAnswere = (params) => {
  return defHttp.delete({ url: Api.updateQuAnswere, params }, { joinParamsToUrl: true,isTransformResponse:false }).then(() => {
  });
}

/**
 * 提交考试
 * @param params
 */
export const submitPaper = (params,closeModal) => {
  return defHttp.delete({ url: Api.submitPaper, params }, { joinParamsToUrl: true,isTransformResponse:false }).then((data) => {
    // console.log(data.result);
    Modal.success({
      title: '提交试卷成功！',
      content: '本次考试得分：'+data.result,
      afterClose() {
        closeModal();
      },
    })
  });
}

/**
 * 查询考试记录
 * @param params
 */
export const queryByExamId = (params) => defHttp.get({ url: Api.queryByEIdAndUId, params },{ joinParamsToUrl: true});


